﻿using System.Collections.Generic;
using System.Data;

namespace ncp.Business
{
    public class LogHandleBll
    {
        /// <summary>
        /// 增加操作日志
        /// </summary>
        public static void AddHandleLog(Dictionary<string, object> dicHandleLog, string pDatabase)
        {
            string mySQL = "INSERT INTO dbo.sa_LogHandle (User_Id, ComputerName, ComputerIP, Handle_Time, Handle_Note, Obj_GUID) " +
                           "VALUES ('" + dicHandleLog["user_id"].ToString() + "', '" + dicHandleLog["computername"].ToString() + "', '" + dicHandleLog["computerip"].ToString() + "', getdate(), '" + dicHandleLog["handle_note"].ToString() + "', '" + dicHandleLog["obj_guid"].ToString() + "')";
            CommonBll.ExecuteNonQuery(mySQL, pDatabase);
        }

        /// <summary>
        /// 得到分页操作日志表
        /// </summary>
        public static DataTable GetHandleLogTable(int piPageIndex, int piPageSize, string pcFieldList, string pcOrderBy, string pcWhere, string pDatabase)
        {
            string sqlStr = CommonBll.GetPagingSQL(piPageIndex, piPageSize, "sa_LogHandle_v", pcFieldList, "Log_Id", pcOrderBy, pcWhere);
            return CommonBll.GetdtList(sqlStr, pDatabase);
        }

        /// <summary>
        /// 得到操作日志表
        /// </summary>
        public static DataTable GetHandleLogTable(string pcWhere, string pcOrderBy, string pDatabase)
        {
            string sqlStr = "select * from sa_LogHandle_v ";
            if (!string.IsNullOrEmpty(pcWhere))
                sqlStr += " where " + pcWhere;
            if (!string.IsNullOrEmpty(pcOrderBy))
                sqlStr += " order by " + pcOrderBy;
            return CommonBll.GetdtList(sqlStr, pDatabase);
        }

        //得到记录数
        public static int GetLogHandleCount(string pcWhere, string pDatabase)
        {
            string sqlStr = "select count(*) from sa_LogHandle ";
            if (!string.IsNullOrEmpty(pcWhere))
                sqlStr += " where " + pcWhere;
            return CommonBll.ReadInteger(sqlStr, pDatabase);
        }
    }
}
